package students_files_test01;

public class HTMLSalesFormatter implements SalesFormatter{

    static public HTMLSalesFormatter singletonInstance = new HTMLSalesFormatter();

    private HTMLSalesFormatter(){

    }

    static public HTMLSalesFormatter getSingletonInstance(){
        return singletonInstance;
    }

    @Override
    public String formatSales(Sales sales) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<html>\n" + "  <body>\n" + "  <center><h2>Orders</h2></center>\n");
        for (Order order : sales){
            double d = 0;
            for (OrderItem orderItem : order){
                d += orderItem.getValue();
            }
            stringBuilder.append("   <hr>\n" + "   <h4>Total = " + d + "</h4>\n");
            for (OrderItem orderItem : order){
                stringBuilder.append("    <p>\n      <b>code:</b> " + orderItem.getProduct().getCode() + "<br>\n"
                + "      <b>quantity:</b> " + orderItem.getQuantity() + "<br>\n" + "      <b>price:</b> "
                        + orderItem.getProduct().getPrice() + "\n" + "    </p>\n");
            }
        }
        stringBuilder.append("  </body>\n" + "</html>\n");
        String s = stringBuilder.toString();
        return s;
    }
}
